package com.nanfang51g3.ckz.ui.forget;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.nanfang51g3.ckz.R;
import com.nanfang51g3.ckz.application.CkzApplication;
import com.nanfang51g3.ckz.ui.base.IPresenter;
import com.nanfang51g3.ckz.ui.base.Base2Activity;
import com.nanfang51g3.ckz.ui.login.LoginActivity;
import com.nanfang51g3.ckz.utils.AppManager;
import com.nanfang51g3.ckz.utils.EasyToast;
import com.nanfang51g3.ckz.utils.KLog;
import com.nanfang51g3.ckz.widget.ClearEditText;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2016/4/19.
 */
public class ForgetPassword3Activity extends Base2Activity implements ForgetPasswordContract.View {
    ForgetPasswordContract.ForgetPasswordActionsListener forgetPasswordActionsListener;
    @Bind(R.id.cet_forget_password3_new)
    ClearEditText cetForgetPassword3New;
    @Bind(R.id.cet_forget_password_confirm)
    ClearEditText cetForgetPasswordConfirm;
    private String phone;
    @Override
    public IPresenter getPresenter() {
        return null;
    }
    @Override
    public int getContentView() {
        return R.layout.forget_password3;
    }

    @Override
    public boolean isShowLeftIcon() {
        return true;
    }

    @Override
    public boolean isShowRightIcon() {
        return false;
    }

    @Override
    public int setLeftIcon() {
        return R.mipmap.ic_accounting_left;
    }

    @Override
    public int setRightIcon() {
        return 0;
    }

    @Override
    public int showTitle() {
        return R.string.str_forget_password;
    }

    @Override
    public void onClickLeft(View v) {
        AppManager.getAppManager().finishActivity(this);
    }

    @Override
    public void onClickRight(View v) {

    }

    @Override
    public void showProgress() {

    }

    @Override
    public void dismissProgress() {

    }

    @Override
    public void startShowView() {
        AppManager.getAppManager().finishAllActivity();
        startActivity(new Intent(ForgetPassword3Activity.this, LoginActivity.class));
    }

    @Override
    public Context getContext() {
        return this;
    }

    @Override
    public void showMessage(String message) {
        EasyToast.showShort(this,message);
    }

    @Override
    public void onIntent() {
        super.onIntent();
        phone = getIntent().getStringExtra("phone");
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        forgetPasswordActionsListener = DaggerForgetPasswordContractComponent
                .builder()
                .appComponent(CkzApplication.getAppComponent())
                .forgetPasswordPresenterModule(new ForgetPasswordPresenterModule(this))
                .build().getForgetPasswordPresenter();
        KLog.i("TAG", forgetPasswordActionsListener == null ? "forgetPasswordActionsListener==null" : "forgetPasswordActionsListener!=null");
        ButterKnife.bind(this);

    }


    @OnClick(R.id.linear_forget_password3)
    public void linear_forget_password3(View v) {
        String password = cetForgetPassword3New.getText().toString().trim();
        String confirmPassword = cetForgetPasswordConfirm.getText().toString().trim();

        /**
         * @see  ForgetPasswordPresenter#forget(String, String, String)
         */
        forgetPasswordActionsListener.forget(phone, password, confirmPassword);

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ButterKnife.unbind(this);//解除绑定，官方文档只对fragment做了解绑
    }
}
